package com.my12306.train.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.my12306.common.constant.CommonConstants;
import com.my12306.common.model.vo.PageVo;
import com.my12306.common.util.PageUtils;
import com.my12306.common.util.response.ResponseData;
import com.my12306.train.dao.MemberDao;
import com.my12306.train.dao.OrderDao;
import com.my12306.train.model.entity.MemberEntity;
import com.my12306.train.model.entity.OrderEntity;
import com.my12306.train.service.MemberService;
import com.my12306.train.service.OrderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;


@Service("memberService")
public class MemberServiceImpl extends ServiceImpl<MemberDao, MemberEntity> implements MemberService {

    @Override
    public PageUtils queryMemberPage(PageVo pageVo) {
        pageVo = pageVo.init();
        List<MemberEntity> memberEntities = this.baseMapper.queryMemberPage(pageVo, CommonConstants.LogicDelete.no_delet.getValue());
        if(memberEntities != null){
            Integer dataCount = queryMemberCount(pageVo, CommonConstants.LogicDelete.no_delet.getValue());
            System.out.println("数据总量：" + dataCount);
            return PageUtils.build(pageVo, memberEntities, dataCount);
        }
        return null;
    }

    @Override
    public Integer queryMemberCount(PageVo pageVo, int logicDelete) {
        Integer count = this.baseMapper.queryMemberCount(pageVo, logicDelete);
        return count;
    }

    @Override
    @Transactional
    public ResponseData deleteMemberBatchByIds(List<Long> memberIds) {
        this.baseMapper.deleteMemberBatchByIds(memberIds, CommonConstants.LogicDelete.delete.getValue());
        return ResponseData.ok();
    }

    @Override
    public void updateMemberById(MemberEntity memberEntity) {
        if(memberEntity != null){
            memberEntity.setUpdateDate(new Date());
            this.baseMapper.updateById(memberEntity);
        }
    }
}
